﻿<template>
	<div class="employee-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="queryParams" ref="queryForm" labelWidth="90">
				<el-row>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
						<el-form-item label="关键字">
							<el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="项目">
							<el-select clearable="" filterable="" v-model="queryParams.projectId" placeholder="请选择项目">
								<el-option v-for="(item, index) in projectProjectIdDropdownList" :key="index" :value="item.value" :label="item.label" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="住建ID">
							<el-input v-model="queryParams.zjEmpID" clearable="" placeholder="请输入住建ID" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="姓名">
							<el-input v-model="queryParams.name" clearable="" placeholder="请输入姓名" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="身份证号">
							<el-input v-model="queryParams.idNum" clearable="" placeholder="请输入身份证号" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
						<el-form-item label="电话">
							<el-input v-model="queryParams.phone" clearable="" placeholder="请输入电话" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
						<el-form-item>
							<el-button-group style="display: flex; align-items: center">
								<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'employee:page'"> 查询 </el-button>
								<el-button icon="ele-Refresh" @click="() => (queryParams = {})"> 重置 </el-button>
								<el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left: 5px"> 高级查询 </el-button>
								<el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left: 5px"> 隐藏 </el-button>
								<el-button type="primary" style="margin-left: 5px" icon="ele-Plus" @click="openAddEmployee" v-auth="'employee:add'"> 新增 </el-button>
							</el-button-group>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" @sort-change="sortChange" border="">
				<el-table-column type="index" label="序号" width="55" align="center" />

				<el-table-column prop="facephoto" label="人脸" show-overflow-tooltip="" width="60" align="center">
					<template #default="scope">
						<!-- <img @click="ShowImge(record.imageBase64)" style="width: 40px; height: 40px" :src="'data:image/jpeg;base64,' + scope.row.facephoto" /> -->
						<div>
							<el-image
								style="width: 42px; height: 42px"
								:src="'data:image/jpeg;base64,' + scope.row.facephoto"
								:zoom-rate="1.2"
								:max-scale="7"
								:min-scale="0.2"
								:preview-src-list="['data:image/jpeg;base64,' + scope.row.facephoto]"
								:initial-index="0"
								:preview-teleported="true"
								fit="cover"
							/>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="name" label="姓名" show-overflow-tooltip="" width="80" align="center" />
				<el-table-column prop="projectId" label="项目" show-overflow-tooltip="" width="260">
					<template #default="scope">
						<span>{{ scope.row.projectIdName }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="zjEmpID" label="住建ID" show-overflow-tooltip="" width="80" align="center" />
				<el-table-column prop="idNum" label="身份证号" show-overflow-tooltip="" width="146" align="center" />
				<!-- <el-table-column prop="age" label="年龄" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="sex" label="性别" show-overflow-tooltip="" width="60" align="center">
					<template #default="scope">
						<el-tag :type="dv('GenderEnum', scope.row.sex)?.tagType"> {{ dv('GenderEnum', scope.row.sex)?.name }}</el-tag>
					</template>
				</el-table-column> -->
				<el-table-column prop="nation" label="民族" show-overflow-tooltip="" width="60" align="center" />
				<el-table-column prop="birthday" label="生日" show-overflow-tooltip="" width="80" align="center" />
				<el-table-column prop="address" label="住址" show-overflow-tooltip="" />
				<!-- <el-table-column prop="native" label="户籍" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="phone" label="电话" show-overflow-tooltip="" /> -->

				<!-- <el-table-column prop="workType" label="工种" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="workGroup" label="工作组" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="emerPeople" label="紧急联系人" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="emerPhone" label="紧急联系人电话" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="culture" label="文化程度" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="health" label="健康状况" show-overflow-tooltip="" /> -->
				<el-table-column prop="qianFaJiGuan" label="签发机关" show-overflow-tooltip="" />
				<!-- <el-table-column prop="iDcard_A" label="身份证正面照" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="iDcard_B" label="身份证反面照" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="qiXianQiShi" label="身份证起始日期" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="qiXianShiXiao" label="身份证失效日期" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="bankName" label="银行名称" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="bankAccount" label="银行账号" show-overflow-tooltip="" /> -->
				<el-table-column prop="isAutoAudit" label="自动审核" show-overflow-tooltip="" width="70" align="center">
					<template #default="scope">
						<el-tag v-if="scope.row.isAutoAudit"> 是 </el-tag>
						<el-tag type="danger" v-else> 否 </el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="isMobile" label="移动打卡" show-overflow-tooltip="" width="70" align="center">
					<template #default="scope">
						<el-tag v-if="scope.row.isMobile"> 是 </el-tag>
						<el-tag type="danger" v-else> 否 </el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="isSendClient" label="下发错误" show-overflow-tooltip="" width="70" align="center">
					<template #default="scope">
						<el-tag v-if="scope.row.isSendClient" type="success"> 是 </el-tag>
						<div type="danger" v-else></div>
					</template>
				</el-table-column>
				<el-table-column prop="sendClientErr" label="错误信息" show-overflow-tooltip="" align="center" />
				<!-- <el-table-column prop="mobileAccount" label="移动端登录账号" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="mobilePassword" label="移动端登录密码" show-overflow-tooltip="" /> -->
				<!-- <el-table-column prop="picLen" label="注册人脸长度" show-overflow-tooltip="" /> -->
				<el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('employee:update') || auth('employee:delete')">
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditEmployee(scope.row)" v-auth="'employee:update'"> 编辑 </el-button>
						<el-button icon="ele-Delete" size="small" text="" type="primary" @click="delEmployee(scope.row)" v-auth="'employee:delete'"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				size="small"
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
			/>
			<printDialog ref="printDialogRef" :title="printEmployeeTitle" @reloadTable="handleQuery" />
			<editDialog ref="editDialogRef" :title="editEmployeeTitle" @reloadTable="handleQuery" />
		</el-card>
	</div>
</template>

<script lang="ts" setup="" name="employee">
import { ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { auth } from '/@/utils/authFunction';

import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
import { formatDate } from '/@/utils/formatTime';

import printDialog from '/@/views/system/print/component/hiprint/preview.vue';
import editDialog from '/@/views/main/employee/component/editDialog.vue';
import { pageEmployee, deleteEmployee } from '/@/api/main/employee';
import { getProjectProjectIdDropdown } from '/@/api/main/employee';

const showAdvanceQueryUI = ref(false);
const printDialogRef = ref();
const editDialogRef = ref();
const loading = ref(false);
const tableData = ref<any>([]);
const queryParams = ref<any>({});
const tableParams = ref({
	page: 1,
	pageSize: 10,
	total: 0,
});

const printEmployeeTitle = ref('');
const editEmployeeTitle = ref('');

// 改变高级查询的控件显示状态
const changeAdvanceQueryUI = () => {
	showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
};

// 查询操作
const handleQuery = async () => {
	loading.value = true;
	var res = await pageEmployee(Object.assign(queryParams.value, tableParams.value));
	tableData.value = res.data.result?.items ?? [];
	tableParams.value.total = res.data.result?.total;
	loading.value = false;
};

// 列排序
const sortChange = async (column: any) => {
	queryParams.value.field = column.prop;
	queryParams.value.order = column.order;
	await handleQuery();
};

// 打开新增页面
const openAddEmployee = () => {
	editEmployeeTitle.value = '添加人员信息';
	editDialogRef.value.openDialog({});
};

// 打开打印页面
const openPrintEmployee = async (row: any) => {
	printEmployeeTitle.value = '打印人员信息';
};

// 打开编辑页面
const openEditEmployee = (row: any) => {
	editEmployeeTitle.value = '编辑人员信息';
	editDialogRef.value.openDialog(row);
};

// 删除
const delEmployee = (row: any) => {
	ElMessageBox.confirm(`确定要删除吗?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			await deleteEmployee(row);
			handleQuery();
			ElMessage.success('删除成功');
		})
		.catch(() => {});
};

// 改变页面容量
const handleSizeChange = (val: number) => {
	tableParams.value.pageSize = val;
	handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
	tableParams.value.page = val;
	handleQuery();
};

const projectProjectIdDropdownList = ref<any>([]);
const getProjectProjectIdDropdownList = async () => {
	let list = await getProjectProjectIdDropdown();
	projectProjectIdDropdownList.value = list.data.result ?? [];
};
getProjectProjectIdDropdownList();

handleQuery();
</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
